package com.tianshi.pxx.mapper;

import com.tianshi.pxx.pojo.entity.Product;
import org.apache.ibatis.annotations.*;

import java.util.List;


@Mapper
public interface ProductMapper {

    @Select("SELECT * FROM product")
    List<Product> selectAll();

    @Select("SELECT * FROM product WHERE name LIKE CONCAT('%', #{keyword}, '%')")
    List<Product> search(String keyword);


    @Delete("DELETE FROM product WHERE id = #{id}")
    int delete(Integer id);

    @Select("SELECT * FROM product WHERE price >= #{minPrice} AND price <= #{maxPrice}")
    List<Product> selectByPrice(@Param("minPrice") Double minPrice, @Param("maxPrice") Double maxPrice);

    @Update("UPDATE product SET name = #{name}, price = #{price}, description = #{description} WHERE id = #{id}")
    void update(Product product);

    @Insert("INSERT INTO product(name, price, description) VALUES(#{name}, #{price}, #{description})")
    void insert(Product product);
}
